package MyText2;

public class MyQueue {
    class Node{
        public int val;
        public Node next;
        public Node(int val){
            this.val= this.val;
        }
    }

    public Node head;
    public Node last;
    public int size;

    public void offer(int val){
        Node node = new Node(val);
        if(head==null){
            head=node;
            last=node;
        }else {
            last.next=node;
            last=node;
        }
        size++;
    }
    public int size(){
        return size;
    }
    public boolean isEmpty(){
        return size==0;
    }
    public int poll(){
        if(isEmpty()){
            throw new EmptyException("栈是空的！");
        }
        int ret=head.val;
        size--;
        head=head.next;
        if(head==null){
            last=null;
        }
        return ret;
    }
    public int peek(){
        if(isEmpty()){
            throw new EmptyException("队列为空");
        }
        int ret=head.val;
        return ret;
    }

}
